'''
QTextDEdit

'''

from PyQt5.QtWidgets import *
import sys

class QTextEditDemo(QWidget):
    def __init__(self):
        super(QTextEditDemo, self).__init__()
        self.initUI()
        self.show()

    def initUI(self):

        self.setWindowTitle("QTextEdit")
        self.resize(300, 300)

        self.textEdit = QTextEdit()
        self.textEdit1 = QTextEdit()
        self.btn0 = QPushButton("显示文本")
        self.btn1 = QPushButton("显示HTML")
        self.btn2 = QPushButton("获取文本")
        self.btn3 = QPushButton("获取HTML")
        self.getText = None
        self.getHTML = None

        layout = QVBoxLayout()
        layout.addWidget(self.textEdit)
        layout.addWidget(self.textEdit1)
        layout.addWidget(self.btn0)
        layout.addWidget(self.btn1)
        layout.addWidget(self.btn2)
        layout.addWidget(self.btn3)

        self.setLayout(layout)
        self.btn0.clicked.connect(self.onClicked_ButtonText)
        self.btn1.clicked.connect(self.onClicked_ButtonHTML)
        self.btn2.clicked.connect(self.onClicked_ButtonGetText)
        self.btn3.clicked.connect(self.onClicked_ButtonGetHTML)
    def onClicked_ButtonText(self):
        self.textEdit.setPlainText("Hello world")

    def onClicked_ButtonGetText(self):
        self.getText = self.textEdit.toPlainText()
        self.textEdit1.setPlainText(self.getText)

    def onClicked_ButtonHTML(self):
        self.textEdit.setHtml('<font color="blue">Hello World</font>')

    def onClicked_ButtonGetHTML(self):
        self.getHTML = self.textEdit.toHtml()
        self.textEdit1.setHtml(self.getHTML)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = QTextEditDemo()

    sys.exit(app.exec_())